package com.iaiai.imail.activity;

import java.util.List;
import java.util.TimerTask;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.iaiai.imail.core.IActivity;
import com.iaiai.imail.core.IServiceFactory;
import com.iaiai.imail.entity.Email;
import com.iaiai.imail.helper.DatabaseOpenHelper;

/**
 * 
 * <p>
 * Title: StartActivity.java
 * </p>
 * <p>
 * E-Mail: 176291935@qq.com
 * </p>
 * <p>
 * QQ: 176291935
 * </p>
 * <p>
 * Http: iaiai.iteye.com
 * </p>
 * <p>
 * Create time: 2012-9-12 上午10:13:01
 * </p>
 * 
 * @author 丸子
 * @version 0.0.1
 */
public class StartActivity extends IActivity {

	private long stopTimer = 3000; // 启动界面停顿时间

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.start);

		// 初始化数据
		IServiceFactory.getInstance(this);
		// 初始化数据库
		DatabaseOpenHelper.getInstance(this);

		// 查询数据
		final List<Email> list = getDao().getEmailDao().queryAll();

		execHandle(new TimerTask() {
			public void run() {
				if (list.size() <= 0) {
					Intent activity = new Intent(StartActivity.this, CreateActivity.class);
					startActivity(activity);
				} else {
					Intent activity = new Intent(StartActivity.this, MainActivity.class);
					startActivity(activity);
				}
				finish();
			}
		}, stopTimer);
	}

}
